﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SRB.Tg.Operate
{
    public class RegHelper
    {
        /// <summary>
        /// 注册表读取数据
        /// </summary>
        /// <param name="node">节点</param>
        /// <param name="name">名称</param>
        /// <returns></returns>
        public static string GetData(string SUB_KEY, string node, string name)
        {
            string version = "";
            RegistryKey SOFTWARE = Registry.CurrentUser.OpenSubKey(SUB_KEY, true);
            RegistryKey tmp = SOFTWARE.OpenSubKey(node, true);
            if(tmp == null)
            {
                return null;
            }

            if ((tmp.GetValue(name) != null) && (tmp.GetValue(name) != System.DBNull.Value))
            {
                version = tmp.GetValue(name).ToString();
            }
            return version;
        }

        /// <summary>
        /// 注册表写入值
        /// </summary>
        /// <param name="node">节点</param>
        /// <param name="name">名称</param>
        /// <param name="value">值</param>
        public static void SetData(string SUB_KEY, string node, string name, object value)
        {
            RegistryKey SOFTWARE = Registry.CurrentUser.OpenSubKey(SUB_KEY, true);
            RegistryKey tmp = SOFTWARE.CreateSubKey(node);
            tmp.SetValue(name, value);
        }
    }
}
